package com.wsoft.system.controller;

import com.wsoft.constant.RedisKeyConstant;
import com.wsoft.core.annotation.GetRedisCache;
import com.wsoft.response.ResponsePage;
import com.wsoft.response.ResponseResult;
import com.wsoft.system.dto.SysPostDTO;
import com.wsoft.system.query.post.SysPostReq;
import com.wsoft.system.service.ISysPostService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 岗位 前端控制器
 * @author juiet
 * @since 2024年09月11日 15:05:53
 */
@RestController
@Tag(name = "岗位管理")
@RequestMapping("/sys/post")
public class SysPostController {

    @Resource
    private ISysPostService postService;
    @Operation(summary = "新增岗位",description = "新增岗位")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody @Valid SysPostDTO dto) {
        boolean b = postService.insert(dto);
        if (b){
            return ResponseResult.success("[sys.msg.success]");
        }
        else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "编辑岗位",description = "编辑岗位")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody @Valid SysPostDTO dto) {
        boolean b = postService.update(dto);
        if (b){
            return ResponseResult.success("[sys.msg.success]");
        }
        else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "删除岗位",description = "删除岗位")
    @GetMapping("/delete")
    public ResponseResult delete(@RequestParam("id") Long id) {
        boolean b = postService.delete(id);
        if (b){
            return ResponseResult.success("[sys.msg.success]");
        }
        else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "查看岗位详情",description = "查看岗位详情")
    @GetMapping("/get")
    public ResponseResult getPost(@RequestParam("id") Long id) {
        return ResponseResult.success(postService.getPost(id));
    }
    @Operation(summary = "全量获取岗位",description = "全量获取岗位")
    @GetMapping("/getAll")
    @GetRedisCache(type = RedisKeyConstant.POST_ALL_CACHE)
    public ResponseResult getAll() {
        return ResponseResult.success(postService.list());
    }
    @Operation(summary = "岗位列表",description = "分页")
    @PostMapping("/list")
    public ResponseResult pageList(@RequestBody @Valid SysPostReq req) {
        return ResponseResult.success(ResponsePage.restPage(postService.pagePost(req)));
    }
}
